package com.akkainaction.router.group.actor.scattergatherfirstcompleted;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.dispatch.OnComplete;
import akka.pattern.Patterns;
import akka.util.Timeout;
import com.typesafe.config.ConfigFactory;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;

public class TestMasterFirstActor {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys", ConfigFactory.load("first-router.conf"));
//        ActorSystem system = ActorSystem.create("sys", ConfigFactory.load("tail-chopping-router.conf"));
        ActorRef masterFirstActor = system.actorOf(Props.create(MasterFirstActor.class), "masterFirstActor");
        Timeout timeout = new Timeout(Duration.create(10, "seconds"));
        Future<Object> fu = Patterns.ask(masterFirstActor, "helloA", timeout);
        fu.onComplete(new OnComplete<Object>() {
            @Override
            public void onComplete(Throwable err, Object result) throws Throwable {
                System.out.println("err: " + err);
                System.out.println("result: " + result);
            }

        }, system.dispatcher());
    }
}
